package cn.starrysky.hrm.usercontext;

import cn.starrysky.hrm.vo.UserContext;
import com.alibaba.fastjson.JSON;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

public class UserContextHolder {
    public static UserContext getUserContext(){
        //从上下文中获取登录对象
        SecurityContext context = SecurityContextHolder.getContext();
        String userContextJson = context.getAuthentication().getPrincipal().toString();
        //转话对象
        return JSON.parseObject(userContextJson, UserContext.class);
    }
}
